package com.xh.petdogexpert.sys.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xh.petdogexpert.base.BaseController;
import com.xh.petdogexpert.base.BaseException;
import com.xh.petdogexpert.base.ResponseData;
import com.xh.petdogexpert.sys.dto.Resource;
import com.xh.petdogexpert.sys.service.IResourceService;

@RequestMapping(value = "sys/")
@Controller
public class ResourceController extends BaseController {

	@Autowired
	IResourceService resourceService;

	@RequestMapping(value = "resource/queryResourcesTree")
	@ResponseBody
	public ResponseData queryResourcesTree(Resource resource) {
		List<Resource> resources = resourceService.queryResourcesTree(resource);
		return new ResponseData(resources);
	}
	
	@RequestMapping(value = "resource/updateResource")
	@ResponseBody
	public ResponseData updateResource(Resource resource) throws BaseException {
		Integer id = resourceService.updateResource(resource);
		return new ResponseData(id);
	}
	
	@RequestMapping(value = "resource/deleteResource")
	@ResponseBody
	public ResponseData deleteResource(Resource resource) throws BaseException {
		Integer id = resourceService.deleteResource(resource);
		return new ResponseData(id);
	}
	
	@RequestMapping(value = "resource/addResource")
	@ResponseBody
	public ResponseData addResource(Resource resource) throws BaseException {
		Integer id = resourceService.addResource(resource);
		return new ResponseData(id);
	}
}
